package com.example.demo_page.controller;

import com.example.demo_page.pojo.User;
import com.example.demo_page.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 */
@Controller
@RequestMapping("/user")

public class UserController {

    @Autowired

    private UserService userService;

    /**

     * @param model

     * @param pageNum  当前页数

     * @return

     */

    @GetMapping("/findAll")
    public String findUser(Model model, @RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum) {
        PageHelper.startPage(pageNum,5);    // 默认从第一页开始，每页展示五条数据

        List<User> userList = userService.getAllUser();

        PageInfo<User> pageInfo = new PageInfo<>(userList);

        model.addAttribute("pageInfo",pageInfo);
        System.out.println(pageInfo);
        return "index";
    }
}   
